//1.基本数据类型
let numQ: number = 123
let strQ: string = 'abc'
let boolQ: boolean = true
let nul: null = null
let undef: undefined = undefined
//2.联合类型
let numStr: (number | string) = 123
numStr = 'abc'
//3.类型推断、字面量类型
let testStr = 'abc'
let testStr1: 1 | 2 | 3

//4.类型别名
type strTypes = string
let strTest1: strTypes = '123'
//必须要有（），|优先级比[]低，没有（）会被理解成number或者string[]
type arrayTypes = (number | string)[]
let arrTypes1: arrayTypes = [1, 2, '123']

//5.数组
let arrQ1: number[] = [123]
let arrQ2: string[] = ['123']
let arrQ3: (number | string)[] = [1, '456']

//6.对象
let objQ: {
    name: string,
    age: number,
    sex?: string
} = {
    name: '张三',
    age: 18,
}

//7.函数
const addQ = (x: number, y: number): number => {
    return x + y
}
const testA = (x: number, y: number): void => {
    console.log(x + y)
}
const testB = (x: number, y: number): undefined => {
    return undefined
}

//8.可选
const testC = (x: number, y?: number): undefined => {
    return undefined
}

//9.接口
interface objInterface {
    name: string,
    age: number,
    sex?: string,
    dept: string,
    unit: string
}
let objInterface: objInterface = {
    name: '',
    age: 0,
    dept: '',
    unit: ''
}

//13.any
let any1:any = 1
any1=true
any1='bb'
any1=['1']

//14.只读
let readOnlyObj:{
    readonly name:string,
    age:number
} = {
    name:'张三',
    age:18
}
// readOnlyObj.name = '李四'
interface abc{
    name:string,
    age:number,
    dept:string
}
interface abc{
    name:string,
    age:number,
    sex:string
}
let person:abc = {
    name:'',
    age:12,
    dept:'',
    sex:''
}


//10.元组
let yuanArr: [number, string] = [1, '2']
yuanArr.push(8)
yuanArr.push('9')

//11.枚举
enum arrEnum { a, b, c }
arrEnum['b'] === 1

//12.泛型
function defineTypes<T>(value:T):T{return value}
let definedStr = defineTypes<string>('2')

//13.索引签名[propName:string]:string
//优点：可以动态的添加和访问对象的属性
//propName表示的是索引签名的名称，只是为了可读性，没有什么意义，可以改成任意名称
interface dataType{
    [propName:string]:string
}
